#include <vector>
#include <string>
using namespace std;

class Solution
{
public:
    string longestCommonPrefix(vector<string> &strs)
    {
        string ret;
        ret = strs[0];
        for (int i = 1; i < strs.size(); ++i)
        {
            auto retbegin = ret.begin();
            auto curbegin = strs[i].begin();
            while (retbegin != ret.end() && curbegin != strs[i].end())
            {
                if (*retbegin != *curbegin)
                {
                    break;
                }
                ++retbegin;
                ++curbegin;
            }
            ret.erase(retbegin, ret.end());
        }
        return ret;
    }
};